import css from './regist.css'
import {Vue,axios,navigation,commonVue,loadsection} from '../../assets/js/base.js';
import upload from  '../../component/upload';
import regist from  '../../API/regist.js';
const config = require('../../../config');
const imgUploadPath = !!process.env  ? config.dev.imgUploadPath : config.build.imgUploadPath;
const imgPath = !!process.env  ? config.dev.imgPath : config.build.imgPath;

new Vue({
    el: '#main',
    data:{
      fullScreen:false,//是否全屏
      currentMenu:"regist.html",//当前菜单
      imgUploadPath:imgUploadPath,
      imgPath:imgPath,
      tableLoading:false,
      pageState:false,
      options:{
        Name:"",//商铺名字
        Tel:"",//手机号
        UserName:"",//用户名
        PassWord:"",//密码
        Avatar:"",//商城图标
        Address:""//公司地址
      },
      loadSection:false,
    },
    mounted:function(){
    },
    methods:{
      globalEvent:function(){
        commonVue.$emit('navSelected');
      },
      checkPermission(){
        return true;
      },
      confirm() {
        console.log(111)
          this.tableLoading = true;

          this.getImgData("upload",(data)=>{
            let banner = "";
            for(let i = 0; i < data.length; i++){
              banner = banner + data[i] + ";";
            }
            this.options.Avatar=banner;
            regist(this.options).then(data => {
              this.tableLoading = false;
              this.$Message({
                  message:"操作成功"
              });
              window.location.href = "./login.html";
            }).catch(message => {
              this.tableLoading = false;
              this.$Message({
                  message
              });
            });
  
          });

        
      },
      getImgData(ref,callback){
        this.$refs[ref].upload(data => {
          if(data.res == "0"){//出错了
            alert(data.mes)
            return;
          }

          let _data = data.imgList;//这个地方是用户新上传的图片地址
          let oldImgpath = data.oldImgpath;//这个地方是编辑的时候传进去的图片地址
          let imgPathList = [];
          for(let i = 0; i < _data.length; i++){
            imgPathList.push(_data[i].value)//保存图片地址
          }
          for(let i = 0; i < oldImgpath.length; i++){
            imgPathList.push(oldImgpath[i])//保存图片地址
          }
          callback(imgPathList);
        });
      },
    },
    components: {
      navigation,
      loadsection,
      upload
    }
})
